<?php
//如果Yaf配置开启了命名空间，需要改成Yaf\Request\Http

class Request extends Yaf_Request_Http
{
    private $_posts;
    private $_params;
    private $_query;

    public function getPost($param = '', $default = '')
    {
        $this->_posts = $this->filter_params($param ? parent::getPost($param, $default) : parent::getPost());
        return $this->_posts;
    }

    public function getParams($param = '', $default = '')
    {
        $this->_params = $this->filter_params($param ? parent::getParams($param, $default) : parent::getParams());
        return $this->_params;
    }

    public function getQuery($param = '', $default = '')
    {
        $this->_query = $this->filter_params($param ? parent::getQuery($param, $default) : parent::getQuery());
        return $this->_query;
    }

    private function filter_params($params)
    {
        if(!is_array($params)){
            return trim($params);
        }
        if($params){
            foreach($params as $key => $val){
                if(is_array($val)){
                    $this->filter_params($val);
                }else{
                    $params[$key] = trim($val);
                }
            }
        }

        return $params;
    }
}
